//
//  main.cpp
//  BinarySearchTree
//
//  Created by 卜绎皓 on 2022/11/7.
//
#include"BinarySearchTree.hpp"

void TestBSTree1()
{
    int a[] = { 5, 3, 4, 1, 7, 8, 2, 6, 0, 9 };
    KEY::BSTree<int> t;
    for (auto e : a)
    {
        t.Insert(e);
    }
    t.InOrder();

    t.Erase(7);
    t.InOrder();

    t.Erase(5);
    t.InOrder();
}
void TestBSTree2()
{
    int a[] = { 5, 3, 4, 1, 7, 8, 2, 6, 0, 9 };
    KEY::BSTree<int> t;
    for (auto e : a)
    {
        t.Insert(e);
    }
    t.InOrder();

    //挨个删除
    for (auto e : a)
    {
        t.Erase(e);
        t.InOrder();
    }
    //先删除左树,再删除根
    /*t.Erase(0);
    t.Erase(1);
    t.Erase(2);
    t.Erase(3);
    t.Erase(4);
    t.Erase(5);
    t.InOrder();*/
}
void TestBSTree3()
{
    int a[] = { 5, 3, 4, 1, 7, 8, 2, 6, 0, 9 };
    KEY::BSTree<int> t;
    for (auto e : a)
    {
        t.InsertR(e);
    }
    t.InOrder();

    //挨个删除
    for (auto e : a)
    {
        t.Erase(e);
        t.InOrder();
    }
    //先删除左树,再删除根
    /*t.Erase(0);
    t.Erase(1);
    t.Erase(2);
    t.Erase(3);
    t.Erase(4);
    t.Erase(5);
    t.InOrder();*/
}
void TestBSTree4()
{
    int a[] = { 5, 3, 4, 1, 7, 8, 2, 6, 0, 9 };
    KEY::BSTree<int> t;
    for (auto e : a)
    {
        t.Insert(e);
    }
    t.InOrder();

    KEY::BSTree<int> copy = t;
    copy.InOrder();

    KEY::BSTree<int> assign;
    assign = t;
    assign.InOrder();
}
int main()
{
    TestBSTree1();
    cout << "-------------------" << endl;
    TestBSTree2();
    cout << "-------------------" << endl;
    TestBSTree3();
    cout << "-------------------" << endl;
    TestBSTree4();

    return 0;
}
